﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using System.Data;
using System.Data.SqlClient;
using System.Text;

namespace tp
{
    public partial class zhuce : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            
        }

       
        protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
        {
            if(rb2.Checked==true)
            {
            string strCn = "Data Source=pc.hstc.cn;Initial Catalog=dhd2014112142;User ID=2014112142;Password=19961124";
            SqlConnection cn = new SqlConnection(strCn);
            try
            {                
                cn.Open();
                string strSql = "select * from guanlogin where Username='" + this.zhucename.Text.ToString() + "'";
                SqlDataAdapter da = new SqlDataAdapter(strSql, cn);
                DataSet ds = new DataSet();
                da.Fill(ds, "guanlogin");
                cn.Close();
                if (ds.Tables["guanlogin"].Rows[0][1].ToString() == this.zhucepassword.Text.ToString())
                {
                    if (this.txtagain.Text.ToString() == this.txtnew.Text.ToString())
                    {
                        cn.Open();
                        string strSql1 = "UPDATE guanlogin SET  Userpassword = '" + this.txtnew.Text.ToString() + "'  where  Username='" + this.zhucename.Text.ToString() + "'";
                        SqlDataAdapter da1 = new SqlDataAdapter(strSql1, cn);
                        DataSet ds1 = new DataSet();
                        da1.Fill(ds1, "guanlogin");
                        cn.Close();
                        Response.Write("<script>alert('请再次登录!'); location.href = '/index.aspx';</script>");
                    }
                    else
                    {
                        lbl.Text="两次输入的密码不一致！";
                    }
                }
                else
                {
                   lbl.Text="原始密码不对！";
                }
            }
            catch (Exception ex)
            {
                lbl.Text=ex.Message.ToString();
            }
            finally
            {
                cn.Close();
            }
        }
            else if (rb1.Checked == true)
            {
                string strCn = "Data Source=pc.hstc.cn;Initial Catalog=dhd2014112142;User ID=2014112142;Password=19961124";
                SqlConnection cn = new SqlConnection(strCn);
                try
                {
                    cn.Open();
                    string strSql = "select * from tplogin where Username='" + this.zhucename.Text.ToString() + "'";
                    SqlDataAdapter da = new SqlDataAdapter(strSql, cn);
                    DataSet ds = new DataSet();
                    da.Fill(ds, "tplogin");
                    cn.Close();
                    if (ds.Tables["tplogin"].Rows[0][1].ToString() == this.zhucepassword.Text.ToString())
                    {
                        //if (this.txtagain.Text.ToString() == this.txtnew.Text.ToString())
                        //{
                            cn.Open();
                            string strSql1 = "UPDATE tplogin SET  Userpassword = '" + this.txtnew.Text.ToString() + "'  where  Username='" + this.zhucename.Text.ToString() + "'";
                            SqlDataAdapter da1 = new SqlDataAdapter(strSql1, cn);
                            DataSet ds1 = new DataSet();
                            da1.Fill(ds1, "tplogin");
                            cn.Close();
                            Response.Write("<script>alert('请再次登录!'); location.href = '/index.aspx';</script>");
                        //}
                        //else
                        //{
                        //    lbl.Text = "两次输入的密码不一致！";
                        //}
                    }
                    else
                    {
                        lbl.Text = "原始密码不对！";
                    }
                }
                catch (Exception ex)
                {
                    lbl.Text = ex.Message.ToString();
                }
                finally
                {
                    cn.Close();
                }
            }
        }

        protected void Timer1_Tick(object sender, EventArgs e)
        {
            this.lbltime.Text = System.DateTime.Now.ToString();
        }

        protected void ibtn_Click(object sender, ImageClickEventArgs e)
        {
            zhucepassword.TextMode = new TextBoxMode();
        }

        protected void ib1_Click(object sender, ImageClickEventArgs e)
        {
            txtnew.TextMode = new TextBoxMode();
        }
        protected void ib2_Click1(object sender, ImageClickEventArgs e)
        {
            txtagain.TextMode = new TextBoxMode();
        }
        }
    }